package com.ruoyi.merchant.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.merchant.domain.PmsCoupon;
import com.ruoyi.merchant.service.PmsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author 28173
 * #Description PmsCouponController
 * #Date: 2025/1/14 10:03
 */
@RestController
@RequestMapping("/coupon")
public class PmsCouponController extends BaseController {
    @Autowired
    private PmsCouponService pmsCouponService;
    /**
     * 优惠券列表
     */
    @PostMapping("/couponList")
    public AjaxResult couponList(PmsCoupon pmsCoupon){
        PageHelper.startPage(pmsCoupon.getPageNum(),pmsCoupon.getPageSize());
        List<PmsCoupon> pmsCouponList = pmsCouponService.couponList(pmsCoupon);
        PageInfo<PmsCoupon> pmsCouponPageInfo = new PageInfo<>(pmsCouponList);
        return AjaxResult.success(pmsCouponPageInfo);
    }

    /**
     * 优惠券状态更改为失效
     * @param id
     * @return
     */
    @GetMapping("/updCouponStatusById/{id}")
    public AjaxResult updCouponStatusById(@PathVariable Integer id){
        pmsCouponService.updCouponStatusById(id);
        return AjaxResult.success();
    }
    /**
     * 删除优惠券
     * @param id
     * @return
     */
    @GetMapping("/couponDelById/{id}")
    public AjaxResult couponDelById(@PathVariable Integer id){
        pmsCouponService.couponDelById(id);
        return AjaxResult.success();
    }
    /**
     * 添加优惠券
     * @param pmsCoupon
     * @return
     */
    @PostMapping("/couponAdd")
    public AjaxResult couponAdd(@RequestBody PmsCoupon pmsCoupon){
        pmsCouponService.couponAdd(pmsCoupon);
        return AjaxResult.success();
    }


    /**
     * 编辑优惠券
     * @param pmsCoupon
     * @return
     */
    @PostMapping("/couponUpd")
    public AjaxResult couponUpd(@RequestBody PmsCoupon pmsCoupon){
        pmsCouponService.couponUpd(pmsCoupon);
        return AjaxResult.success();
    }

    /**
     * 复制优惠券
     * @param pmsCoupon
     * @return
     */
    @PostMapping("/couponCopy")
    public AjaxResult couponCopy(@RequestBody PmsCoupon pmsCoupon){
        pmsCouponService.couponCopy(pmsCoupon);
        return AjaxResult.success();
    }
}
